/**
	This file is part of MemoryTrace.

	MemoryTrace is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

        Contributed by Ameziane NAIT ABDELAZIZ.
        
	MemoryTrace is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
**/

/*! \file TxtLogger.h
    \brief Une classe permettant de logger les allocations au format txt
*/

#ifndef TXTLOGGER_H
#define	TXTLOGGER_H
#include "ILogger.hpp"
#include <unistd.h>
#include <cassert>
#include "alloc_stats.h"



/**
 *\class XmlLogger
 *\brief Ecrit un rapport des allocation sur le tas au format txt tokenisé dans 
 *       le de fichier de sortie. 
 * malloc-> m|120|0x1223434AC
 * calloc-> c|40|10|0x123OO499
 * realloc-> r|0x12233|45|0x12233
 * free   -> f|0x3244AD
 */

class TxtLogger : virtual public ILogger{
    
private:
 /**
  *\brief
  */
  FILE * out;
  
  /**
   * \brief
   */
  char path[50];
 
  /**
   * \brief
   */
  void openFile();
  
  /**
   * \brief
   */
  string bin;
  
  
public:
    TxtLogger(string & bin);
    TxtLogger(const TxtLogger& orig);
    virtual ~TxtLogger();

  /**
   *\brief ouvre l'element malloc
   */
  void startMalloc(void* addr,size_t size,unsigned int index,int tmm);
  
  /**
   *\brief ouvre l'element calloc
   */
  void startCalloc(void* addr,size_t nmemb,size_t size,int compteur_calloc,unsigned int memory_allocation);
  
  /**
   *\brief ouvre l'element realloc
   */
  void startRealloc(void*  v,void*  ret,size_t n,int id,size_t tm);
  
  /**
   *\brief ouvre l'element free
   *@see readAndDump()
   */
  void startFree(void* addr,unsigned nbfree);
  
  /**
   *\brief termine et ferme le document
   */
  void finalizeLog(alloc_stats &st);
  
  /**
   *\brief ferme un element type
   */
  void endElement(const char *type);
};

#endif	/* TXTLOGGER_H */

